package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.clazz.DateTimeClass;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: wufeng
 * @date: 2018/8/22 15:00
 * @desrcption:
 */
public enum DateTimeEnum {

    /**
     * 日期
     */
    TIME("yyyy-MM-dd", "enum.dateTime.name.time", "yyyy-MM-dd"),
    /**
     * 日期时间
     */
    DATETIME("yyyy-MM-dd HH:mm:ss", "enum.dateTime.name.datetime","yyyy-MM-dd HH:mm" );

    private String format;

    private String name;
    /**
     * 前端对应的格式
     */
    private String type;

    DateTimeEnum(String format, String name, String type) {
        this.format = format;
        this.name = name;
        this.type = type;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static List<DateTimeClass> list(){
        List<DateTimeClass> list = new ArrayList<>();
        for (DateTimeEnum p : values()) {
            DateTimeClass dateTimeClass = new DateTimeClass();
            dateTimeClass.setFormat(p.getFormat());
            dateTimeClass.setName(p.getName());
            list.add(dateTimeClass);
        }
        return list;
    }

    public static DateTimeEnum getExcelFormat(String format){
        for (DateTimeEnum dateTime: values()) {
            if(dateTime.getFormat().equals(format)){
                return dateTime;
            }
        }
        return null;
    }
}
